/*
 * WebThings Gateway Constants.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import path from 'path';

// Web server routes
export const USERS_PATH = '/users';
export const THINGS_PATH = '/things';
export const GROUPS_PATH = '/groups';
export const PROPERTIES_PATH = '/properties';
export const NEW_THINGS_PATH = '/new_things';
export const ADAPTERS_PATH = '/adapters';
export const ADDONS_PATH = '/addons';
export const NOTIFIERS_PATH = '/notifiers';
export const ACTIONS_PATH = '/actions';
export const EVENTS_PATH = '/events';
export const LOGIN_PATH = '/login';
export const LOG_OUT_PATH = '/log-out';
export const SETTINGS_PATH = '/settings';
export const UPDATES_PATH = '/updates';
export const UPLOADS_PATH = '/uploads';
export const MEDIA_PATH = '/media';
export const RULES_PATH = '/rules';
export const OAUTH_PATH = '/oauth';
export const OAUTHCLIENTS_PATH = '/authorizations';
export const INTERNAL_LOGS_PATH = '/internal-logs';
export const LOGS_PATH = '/logs';
export const PUSH_PATH = '/push';
export const PING_PATH = '/ping';
export const WELL_KNOWN_PATH = '/.well-known';
export const PROXY_PATH = '/proxy';
export const EXTENSIONS_PATH = '/extensions';
// Remember we end up in the build/* directory so these paths looks slightly
// different than you might expect const
export const STATIC_PATH = path.join(__dirname, '../static');
export const BUILD_STATIC_PATH = path.join(__dirname, '../build/static');
export const VIEWS_PATH = path.join(__dirname, '../build/views');

// Plugin and REST/websocket API things
export const ACTION_STATUS = 'actionStatus';
export const ADAPTER_ADDED = 'adapterAdded';
export const ADD_EVENT_SUBSCRIPTION = 'addEventSubscription';
export const API_HANDLER_ADDED = 'apiHandlerAdded';
export const CONNECTED = 'connected';
export const ERROR = 'error';
export const EVENT = 'event';
export const MODIFIED = 'modified';
export const NOTIFIER_ADDED = 'notifierAdded';
export const OUTLET_ADDED = 'outletAdded';
export const OUTLET_REMOVED = 'outletRemoved';
export const PAIRING_TIMEOUT = 'pairingTimeout';
export const PROPERTY_CHANGED = 'propertyChanged';
export const PROPERTY_STATUS = 'propertyStatus';
export const REMOVED = 'removed';
export const REQUEST_ACTION = 'requestAction';
export const SET_PROPERTY = 'setProperty';
export const THING_ADDED = 'thingAdded';
export const THING_MODIFIED = 'thingModified';
export const THING_REMOVED = 'thingRemoved';
export const GROUP_ADDED = 'groupAdded';
export const GROUP_MODIFIED = 'groupModified';
export const GROUP_REMOVED = 'groupRemoved';
export const LAYOUT_MODIFIED = 'layoutModified';

// OAuth things
export const ACCESS_TOKEN = 'access_token';
export const AUTHORIZATION_CODE = 'authorization_code';
export const USER_TOKEN = 'user_token';
export const READWRITE = 'readwrite';
export const READ = 'read';

// Logging
export enum LogSeverity {
  DEBUG = 0,
  INFO = 1,
  WARNING = 2,
  ERROR = 3,
  PROMPT = 4,
}

// Thing description things
export enum WoTOperation {
  OBSERVE_PROPERTY = 'observeproperty',
  UNOBSERVE_PROPERTY = 'unobserveproperty',
  READ_ALL_PROPERTIES = 'readallproperties',
  WRITE_MULTIPLE_PROPERTIES = 'writemultipleproperties',
  OBSERVE_ALL_PROPERTIES = 'observeallproperties',
  UNOBSERVE_ALL_PROPERTIES = 'unobserveallproperties',
  SUBSCRIBE_ALL_EVENTS = 'subscribeallevents',
  UNSUBSCRIBE_ALL_EVENTS = 'unsubscribeallevents',
  QUERY_ALL_ACTIONS = 'queryallactions',
}
export enum ActionStatusValues {
  PENDING = 'pending',
  RUNNING = 'running',
  COMPLETED = 'completed',
  FAILED = 'failed',
}

// Contexts
export const MOZ_IOT_CONTEXT = 'https://iot.mozilla.org/schemas';
export const WEBTHINGS_CONTEXT = 'https://webthings.io/schemas';
export const WOT_TD_NS_CONTEXT = 'http://www.w3.org/ns/td';
export const WOT_TD_1_CONTEXT = 'https://www.w3.org/2019/wot/td/v1';
export const WOT_TD_1_1_CONTEXT = 'https://www.w3.org/2022/wot/td/v1.1';
export const DEFAULT_CONTEXT = [WOT_TD_1_1_CONTEXT, WEBTHINGS_CONTEXT];

// Profiles
export const WOT_HTTP_BASIC_PROFILE = 'https://www.w3.org/2022/wot/profile/http-basic/v1';
export const WOT_HTTP_SSE_PROFILE = 'https://www.w3.org/2022/wot/profile/http-sse/v1';

export interface LogMessage {
  severity: LogSeverity;
  message: string;
  url?: string;
}

export const UNLOAD_PLUGIN_KILL_DELAY = 3000;
export const DEVICE_REMOVAL_TIMEOUT = 30000;
